<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>
</head>

<body>
  <script>
    // 获取cookie 
    console.log(document.cookie) //获取所有cookie 
    // password=123456; age=88; sex=男; wdcid=3bae49eda6e70470; wdlast=1602575800
    // sex  ---》  男   
    function getCookie(key) {
      var cookie = document.cookie;
      var cookiearr = cookie.split("; ");//["password=123456","age=88","sex=男"]
      for (var i = 0; i < cookiearr.length; i++) {
        var newarr = cookiearr[i].split("=")
        if (key == newarr[0]) {
          return newarr[1]
        }
      }
    }
    console.log(getCookie("sex"))




  </script>
</body>

</html>